const App = getApp();
Page({
  data: {
    xuehao:'',
    jianJF:'',
    jianBZ:'',
    jifenArr:[],
    isData: false,
    userObj:{},
    isRunning:false,

    YU:'',
  },
  onLoad(options) {
   // 设置navbar标题、颜色
   App.setNavigationBar();
   this.setData({YU:App.YU});
  },
  onShow() {
    let _this = this;
    App.pageOnLoad(this);
  },
  getUserAndPoints(xuehaoStr) {
    let _this = this;
    this.setData({isData:false});
    App._get('user.index/detail333', {uid:xuehaoStr}, function(result) {
      let data = result.data;
      _this.setData(data);
      if(data.userObj.user_id>0){
        _this.setData({userObj:data.userObj, isData:true});
      }
      if(data.jifenArr.length>0){
        _this.setData({jifenArr:data.jifenArr});
      }
    });
  },
  xuehaoIn(e) { this.setData({ xuehao: e.detail.value }); },
  jianJFIn(e) { this.setData({ jianJF: e.detail.value }); },
  jianBZIn(e) { this.setData({ jianBZ: e.detail.value }); },
  findUser(){
    var xuehaoStr = this.data.xuehao.trim();
    if(xuehaoStr==''){
      App.showError("请填写要兑换的用户学号");
    }
    else{
      //console.log('aaaaaaaa');
      this.getUserAndPoints(xuehaoStr);
    }
  },
  submitDuiHuan(){
    let _this = this;
    var jianJF = this.data.jianJF.trim();
    var jianBZ = this.data.jianBZ.trim();
    if(jianJF=='' || jianBZ==''){
      App.showError("请填写减扣积分和礼品备注");
    }
    else{
      var xuehaoStr = _this.data.userObj.user_id;
      if(this.data.isRunning==false){
        this.setData({isRunning:true});
      
        App._get('user.index/duihuanJifen', {manUid:wx.getStorageSync('user_id'), uid:xuehaoStr, fen:jianJF, beizhu:jianBZ}, function(result) {
          _this.setData({isRunning:false});
          let data = result.data;
          if(data.backok=='ok'){
            App.showError("积分减扣兑换成功",function(){
            //App.showSuccess("兑换成功",function(){
              _this.setData({jianJF:'',jianBZ:''});
              _this.getUserAndPoints(xuehaoStr);
            });
          }
        });
      }
    }
  }
})